<template>
  <view class="addr-container">
    <view class="info" @click="switchPage">
      <text class="addr">{{address.addr}}{{address.detail}}</text>
      <view class="userInfo">
        <text>{{address.name}}</text>
        <text>{{address.tel}}</text>
      </view>
    </view>
    <view class="right-icon">
      <uni-icons type="compose" size="20" @click="editAddr"></uni-icons>
    </view>
  </view>
</template>

<script>
  const utils = require('@/common/tools')
  import {setUserInfo} from '@/common/storage.js'
  export default {
    name: "address-item",
    provide(){
      return {
        isEdit: false
      }
    },
    props:{
      address: {
        type: Object,
        default: {}
      },
      index:{
        type: Number
      }
    },
    data() {
      return {

      };
    },
    methods:{
      editAddr(){
        utils._navigatorTo('/subPackages/add-address/add-address',{...this.address,index:this.index})
      },
      // 点击地址信息，跳转到购物车页面，将当前地址信息存到本地
      switchPage(){
        // 跳转页面之前将地址信息存到本地
        setUserInfo(this.address)
        this.isEdit = true
        uni.reLaunch({
          url: '/pages/car/car'
        })
        // utils._switchTab('/pages/car/car')
      }
    }
  }
</script>

<style lang="scss">
  .addr-container{
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin: 0 10px;
    font-size: 16px;
    // height: 60px;
    padding: 10px 0;
    border-bottom: 1px solid #eee;
    .info{
      .addr{
        font-weight: 700;
      }
     .userInfo{
       font-size: 14px;
       color: #666;
       margin-top: 8px;
       text{
         margin-right: 10px;
       }
     } 
    }
  }

</style>
